<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-card">
				<div class="layui-card-header table-operate-btn">
					<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='alladd'>添加信息</button>
					<button class="layui-btn layui-btn-danger layui-btn-sm" data-type="del">删除</button>
					<!--<button class="layui-btn layui-btn-danger layui-btn-sm" data-type='off'>一键禁用</button>
					<button class="layui-btn layui-btn-container layui-btn-sm" data-type='on'>一键启用</button>-->
				</div>
				<div class="layui-card-body"> 
					<div class="layui-row layui-col-space15">
						<div class="layui-btn-sm12 layui-col-md12 layui-col-xs12">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">店铺状态：</label>
									<div class="layui-input-inline">
										<select name="status" class="on_off" lay-filter='goods_status'></select>
									</div>
								</div>
 
								<div class="layui-inline search_inline">
									<label class="layui-form-label">店铺名称：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" name="keyword" placeholder="店铺名称" autocomplete="off">
									</div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->
							<table id="test-table-operate" lay-filter="test-table-operate"></table>
							 
							<script type="text/html" id="test-table-operate-barDemo">
								<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
								{{# if(d.status == 0 ) {}}
									<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
								{{# }}}
							</script>
						</div>
					</div>
				</div>
				
			</div>
			<!--商品信息模板-->
			<!-- 主图 -->
			<script type="text/html" id="test-table-operate-img"> 
				<img src={{d.goods_image_url}} />
			</script>
			<!-- 视频 -->
			<script type="text/html" id="test-table-operate-video"> 
				<video>
					<source src="{{d.video_url}}"></source>
				</video>
			</script>
			
			 
			<script type="text/html" id="zizeng">
				{{d.LAY_TABLE_INDEX+1}}
			</script>

			<script src="../../../layuiadmin/layui/layui.js"></script>
			<script src="../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
			<script src="../../../js/common.js" type="text/javascript" charset="utf-8"></script>
			<script>
				layui.config({
					base: '../../../layuiadmin/' //静态资源所在路径
				}).extend({
					index: 'lib/index' //主入口模块
				}).use(['index', 'table', 'tree'], function() {
					var $ = layui.$,
						form = layui.form,
						tree = layui.tree,
						table = layui.table; 
						initdata()
					//用户管理
					function initdata() { 
						table.render({
							elem: '#test-table-operate',
							url: server.sys_work_order_query,
							height: 'full-150',
							//totalRow: true,
							cols: [
								[{
								width: 50,
								field: 'zizeng',
								title: '#',
								fixed: 'left',
								templet: '#zizeng'
							},{
								type: 'checkbox',
								fixed: 'left',
								width: 50,
							},{
									width: 180,
									align: 'center',
									toolbar: '#test-table-operate-barDemo',
									title: '操作',
									totalRowText: '合计：',
									fixed: 'left'
							},
  							{
								field: 'userNo',
								width: 100,
								title: '用户号',
							},{
								field: 'addrId',
								width: 100,
								title: '地址Id',
							},{
								field: 'addrDes',
								width: 100,
								title: '地址描述',
							},{
								field: 'meterId',
								width: 100,
								title: '表具id',
							},{
								field: 'contractor',
								width: 100,
								title: '联系人',
							},{
								field: 'contractPhone',
								width: 100,
								title: '联系电话',
							},{
								field: 'sparePhone',
								width: 100,
								title: '备用电话',
							},{
								field: 'content',
								width: 100,
								title: '问题描述',
							},{
								field: 'remark',
								width: 100,
								title: '备注',
							},{
								field: 'preTime',
								width: 100,
								title: '预约时间',
							},
  							{
								field: 'woType',
								width: 100,
								title: '工单类型',
							},{
								field: 'priorityLevel',
								width: 100,
								title: '紧急程度',
							},{
								field: 'staffId',
								width: 100,
								title: '坐席员工id',
							},{
								field: 'ptId',
								width: 100,
								title: '咨询问题',
							},{
								field: 'replyDes',
								width: 100,
								title: '回复内容',
							},{
								field: 'complaintDept',
								width: 100,
								title: '投诉部门id',
							},{
								field: 'complaintStaff',
								width: 100,
								title: '投诉员工id',
							},
  
  
  							{
								field: 'addby',
								width: 100,
								title: '创建人',
							}, {
								field: 'addtime',
								width: 160,
								title: '创建时间',
							}, {
								field: 'editby',
								width: 100,
								title: '更新人',
							}, {
								field: 'edittime',
								width: 160,
								title: '更新时间',
							}]
							],
							page: true,
							limit: limit,
							limits: limits,
							request: {
								pageName: 'page',
								limitName: 'size',
							},
							parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
								return {
									"code": res.code, //解析接口状态
									"msg": res.msg, //解析提示文本
									"count": res.work_order.pager.total, //解析数据长度
									"data": res.work_order.data //解析数据列表
								};
							},
						});
					}
					//监听搜索
					form.verify({
						memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
							if(!value) {
								return '姓名不能为空';
							}
						}
					});

					//监听搜索
					form.on('submit(search)', function(data) {
						_data = data.field
						initdata();
						return false;
					});

					$("button[type=reset]").on("click", function() {
						_data = {}
						initdata();
						document.getElementById("form").reset();
					});
					//监听工具条
					table.on('tool(test-table-operate)', function(obj) {
						var data = obj.data;
						if(obj.event === 'edit') {
							layer.open({
								type: 2,
								title: '修改',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'model/edit_add.html?shopid=' + data.shopid+'&id='+data.id,
								end: function() {}
							});
						}else if(obj.event === 'del') {
							var data = obj.data;
							console.log(data)
							var id = data.shopid
							layer.confirm('确定要删除该店铺？', function(index) {
								
								submitDelete(id, 0)
								
							}, function() {
								initdata();
								layer.msg('取消操作');
							});
							
						}  
					}); 
					
					function submitDelete(id) {
						$.post(server.sys_work_order_delete, {
							id: id
						}, function(res, status) {
							if(status == 'success') {
								if(res.code == 0) {
									layer.alert('操作成功', function() {
										layer.closeAll(); 
										table.reload('test-table-operate');
									});
								} else {
									layer.msg(res.msg);
									layer.closeAll('loading');
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}
					
					//事件
					var active = {
						batchdel: function() {
						
						},
						del: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = JSON.stringify(checkStatus.data);
							var id = "";
							for(var i = 0; i < checkStatus.data.length; i++) {
								orderid += checkStatus.data[i].orderid;
								if(i != checkStatus.data.length - 1) {
									id += ",";
								}
							}
							if(checkStatus.data.length == 0) {
								layer.msg('至少选择一条')
							} else {
								layer.confirm('确定要删除所选的' + checkStatus.data.length + '条数据？', function() {
									$.ajax({
										url: server.sys_work_order_delete,
										type: 'post',
										dataType: 'json',
										data: "id=" + id,
										success: function(data) {
											if(data.code == '0') {
												layer.msg('删除成功');
												initdata();
											} else {
												layer.msg('删除失败');
												initdata();
											}
										},
										'error': function() {
											layer.msg('系统错误');
											initdata();
										}
									})
								});
							}
						},
						alladd: function() {
							layer.open({
								type: 2,
								title: '添加商品',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'model/edit_add.html',
								success: function(layero, index) {
									var iframe = window['layui-layer-iframe' + index]
								},
								end: function() {}
							});
						},
						on: function() {
							  edit_status(1,"启用")
						},
						off: function() {
							  edit_status(0,"禁用")
						},
					}
					$('.table-operate-btn .layui-btn').on('click', function() {
						var type = $(this).data('type');
						active[type] ? active[type].call(this) : '';
					});
				});
			</script>
	</body>

</html>